﻿using Neudesic.Pulse.Entities;
using Neudesic.Pulse.Infrastructure;
using Neudesic.Pulse.ViewModels;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace Neudesic.Pulse.Views
{
    /// <summary>
    /// Interaction logic for ActivityListView.xaml
    /// </summary>
    [ViewExport(RegionName = RegionNames.ActivityRegion)]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class ActivityListView : UserControl
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivityListView" /> class.
        /// </summary>
        public ActivityListView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Sets the view model.
        /// </summary>
        /// <value>The view model.</value>
        [Import]
        public ActivityListViewModel ViewModel
        {
            set
            {
                this.DataContext = value;
            }
        }

        private void RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            // Fire up a browser window.
            StartProcess(e.Uri.ToString());
        }

        private void linkShareBorder_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ActivityViewModel vm = ((Border)sender).DataContext as ActivityViewModel;
            if (vm != null)
            {
                StartProcess(vm.Activity.Link);
            }
        }

        private void StartProcess(string process)
        {
            System.Diagnostics.Process.Start(process);
        }

    }
}
